package cn.gov.pbc.gd.credit.web.controller.file;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.liu.jbase.ResultVo;
import com.liu.jbase.controller.impl.BaseControllerImpl;
import com.liu.tools.StrUtil;
import com.liu.tools.WebHelper;

import cn.gov.pbc.gd.credit.dfs.service.file.IFileService;
import cn.gov.pbc.gd.credit.vo.file.FileVo;
import cn.gov.pbc.gd.credit.vo.file.ResFileVo;

@Controller
@RequestMapping("/file")	
public class FileController extends BaseControllerImpl<ResFileVo, FileVo, IFileService> {

	@Autowired
	private IFileService fileService;
	
	@ResponseBody
    @RequestMapping("/upload")
	public ResultVo<ResFileVo> upload(FileVo vo, HttpServletRequest request){
		
		return fileService.add(vo, request);
	}

	@ResponseBody
    @RequestMapping("/upload/base64")
	public ResultVo<List<ResFileVo>> uploadBse64(FileVo vo, HttpServletRequest request){
		
		String body = WebHelper.getHttpBody(request);
		if(StrUtil.isNotNull(body)){
			vo = JSON.parseObject(body, FileVo.class);
		}
		
		return fileService.addBase64File(vo, request);
	}
	
    @RequestMapping("/download")
    public void download(FileVo fileVo, HttpServletRequest request, HttpServletResponse response) throws Exception {  
    	
		 fileService.download(fileVo, request, response);
    } 
  
}
